package com.example.travelservlet.collectionFood.service;

import com.example.travelservlet.collectionFood.repository.CollectionFoodRepository;
import com.example.travelservlet.entity.CollectionFood;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CollectionFoodServiceImpl implements CollectionFoodService{
    @Autowired
    private CollectionFoodRepository collectionFoodRepository;


    @Override
    public List<String> findFoodIdsByCollectId(String collectId) {
        List<CollectionFood> collectionFoods = collectionFoodRepository.findCollectionFoodsByCollectId(collectId);
        List<String> foodIds = new ArrayList<>();
        for (CollectionFood collectionFood : collectionFoods){
            foodIds.add(collectionFood.getFoodId());
        }
        return foodIds;
    }

    @Override
    public CollectionFood addCollectionFood(CollectionFood collectionFood) {
        return collectionFoodRepository.save(collectionFood);
    }
}
